<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<style>
    .input-gray {
        background-color: #E0EEEE;
    }
</style>

<h4>数据信息
    <div class="fr">
        <c:if test="${isEdit}">
            <a href="javascript:void(0)" class="dggui-icon-btn" onclick="editForm.init(this,{form:'#dataInfo'})"><i
                    class="iconfont icon-bianji1"></i><span>编辑</span></a>
        </c:if>
    </div>
</h4>
<form action="" id="dataInfo">
    <table class="dggui-table-info edit">
        <tbody>
        <tr>
            <th>接单时间：</th>
            <td>
                <p><fmt:formatDate value="${order.receiveOrderDate}" type="both" pattern="yyyy-MM-dd"/></p>
                <input id="receiveOrderDate" name="receiveOrderDate" type="text" class="dggui-input input-gray" readonly
                       value="<fmt:formatDate value="${order.receiveOrderDate}" type="both" pattern="yyyy-MM-dd"/>">
            </td>
            <th>流程人员：</th>
            <td>
                <p>${order.flowUserName}</p>
                <input id="flowUserName" name="flowUserName" type="text" class="dggui-input input-gray" readonly
                       value="${order.flowUserName}">
            </td>
            <th>产品：</th>
            <td>
                <p>${order.businessProductName}</p>
                <input id="businessProductName" name="businessProductName" type="text" class="dggui-input input-gray"
                       readonly value="${order.businessProductName}">
            </td>
            <th>服务合同编号：</th>
            <td>
                <p>${order.contractNo}</p>
                <input id="contractNo" name="contractNo" type="text" class="dggui-input input-gray" readonly
                       value="${order.contractNo}">
            </td>
        </tr>
        <tr>
            <th>渠道：</th>
            <td>
                <p>${order.channelName}</p>
                <input id="channelName" name="channelName" type="text" class="dggui-input input-gray" readonly
                       value="${order.channelName}">
            </td>
            <th>支行：</th>
            <td>
                <p>${order.subBranch}</p>
                <input id="subBranch" name="subBranch" type="text" class="dggui-input" value="${order.subBranch}"
                       maxlength="100">
            </td>
            <th>资金用途（经营/消费）：</th>
            <td>
                <p><c:if test="${order.purpose==1}">消费</c:if><c:if test="${order.purpose==2}">经营</c:if></p>
                <select name="purpose" id="purpose" class="dggui-select">
                    <option value="">请选择</option>
                    <option value="1" <c:if test="${order.purpose==1}"> selected="selected" </c:if> >消费</option>
                    <option value="2" <c:if test="${order.purpose==2}"> selected="selected" </c:if> >经营</option>
                </select>
            </td>
            <th>需求金额(元)：</th>
            <td>
                <p>${order.loanAmount}</p>
                <input id="loanAmount" name="loanAmount" type="text" class="dggui-input" value="${order.loanAmount}">
            </td>
        </tr>
        <tr>
            <th>产权性质：</th>
            <td>
                <p><c:if test="${order.interestType==1}">住宅</c:if>
                    <c:if test="${order.interestType==2}">商铺</c:if>
                    <c:if test="${order.interestType==3}">公寓</c:if>
                </p>
                <select name="interestType" id="interestType" class="dggui-select">
                    <option value="">请选择</option>
                    <option value="1" <c:if test="${order.interestType==1}"> selected="selected" </c:if> >住宅</option>
                    <option value="2" <c:if test="${order.interestType==2}"> selected="selected" </c:if> >商铺</option>
                    <option value="3" <c:if test="${order.interestType==3}"> selected="selected" </c:if> >公寓</option>
                </select>
            </td>
            <th>抵押物地址：</th>
            <td colspan="5">
                <p>${order.mortgageAddress}</p>
                <input id="mortgageAddress" name="mortgageAddress" type="text" class="dggui-input"
                       value="${order.mortgageAddress}" style="max-width: 100%" maxlength="100">
            </td>
        </tr>
        <tr>
            <th>利息：</th>
            <td style="display: flex;">
                <p>${order.serviceCharge}&nbsp;%&nbsp;&nbsp;&nbsp;&nbsp;${order.rateTypeName}</p>
                <div style="width:50%;max-width:80px;display: none">
                    <input id="serviceCharge" name="serviceCharge" type="text" class="dggui-input"
                           style="width:100%;min-width: 50px;" value="${order.serviceCharge}">
                </div>
                <div style="width:10%;line-height: 30px; display: none">
                    &nbsp;&nbsp;<span>%</span>
                </div>
                <div style="width:40%;display: none">
                    <select name="rateType" id="rateType" class="dggui-select" style="width:100%;">
                    </select>
                </div>
            </td>
            <th>评估公司：</th>
            <td>
                <p>${order.escrowCompany}</p>
                <input id="escrowCompany" name="escrowCompany" type="text" class="dggui-input"
                       value="${order.escrowCompany}" maxlength="200">
            </td>
            <th>评估费用：</th>
            <td>
                <p>${order.appraisalCost}</p>
                <input id="appraisalCost" name="appraisalCost" type="text" class="dggui-input"
                       value="${order.appraisalCost}">
            </td>
            <th>征信：</th>
            <td>
                <p>${order.credit}</p>
                <select name="credit" id="credit" class="dggui-select">
                    <option value="">请选择</option>
                    <option value="好" <c:if test="${order.credit=='好'}"> selected="selected" </c:if> >好</option>
                    <option value="差" <c:if test="${order.credit=='差'}"> selected="selected" </c:if> >差</option>
                </select>
                <%-- <input id="credit" name="credit" type="text" class="dggui-input" value="${order.credit}" maxlength="250">--%>
            </td>
        </tr>
        <tr>
            <th>三方卡：</th>
            <td>
                <p id="thirdparty_name_and_number"><c:if test="${empty order.thirdpartyName}"></c:if>${order.thirdpartyName}<c:if test="${!empty order.thirdpartyNumber}">
                    /</c:if>
                ${order.thirdpartyNumber}</p>
                <input name="thirdpartyNumber" id="thirdpartyNumber" type="hidden" data-old="${order.thirdpartyNumber}"
                       value="${order.thirdpartyNumber}">
                <input name="thirdpartyName" id="thirdpartyName" type="hidden" data-old="${order.thirdpartyName}"
                       value="${order.thirdpartyName}">
            </td>
            <th>申请贷款金额(元)：</th>
            <td>
                <p>${order.appliedAmount}</p>
                <input id="appliedAmount" name="appliedAmount" type="text" class="dggui-input"
                       value="${order.appliedAmount}">
            </td>
            <th>签申请时间：</th>
            <td>
                <p><fmt:formatDate value="${order.applicationTime}" type="both" pattern="yyyy-MM-dd"/></p>
                <input id="applicationTime" name="applicationTime" type="text" class="dggui-input"
                       value="<fmt:formatDate value="${order.applicationTime}" type="both" pattern="yyyy-MM-dd"/>">
            </td>
            <th>报审时间：</th>
            <td>
                <p><fmt:formatDate value="${order.reportTime}" type="both" pattern="yyyy-MM-dd"/></p>
                <input id="reportTime" name="reportTime" type="text" class="dggui-input"
                       value="<fmt:formatDate value="${order.reportTime}" type="both" pattern="yyyy-MM-dd"/>">
            </td>
        </tr>
        <tr>
            <th>审核通过时间：</th>
            <td>
                <p><fmt:formatDate value="${order.approveTime}" type="both" pattern="yyyy-MM-dd"/></p>
                <input id="approveTime" name="approveTime" type="text" class="dggui-input"
                       value="<fmt:formatDate value="${order.approveTime}" type="both" pattern="yyyy-MM-dd"/>">
            </td>
            <th>审过金额(元)：</th>
            <td>
                <p>${order.approveMoney}</p>
                <input id="approveMoney" name="approveMoney" type="text" class="dggui-input"
                       value="${order.approveMoney}">
            </td>
            <th>按揭/全款：</th>
            <td>
                <p><c:if test="${order.refundType==1}">按揭</c:if><c:if test="${order.refundType==2}">全款</c:if></p>
                <select id="refundType" name="refundType" class="dggui-select">
                    <option value="">请选择</option>
                    <option value="1" <c:if test="${order.refundType==1}"> selected="selected" </c:if> >按揭</option>
                    <option value="2" <c:if test="${order.refundType==2}"> selected="selected" </c:if> >全款</option>
                </select>
            </td>
            <th>是否垫资：</th>
            <td>
                <p><c:if test="${order.advanceFund==1}">否</c:if><c:if test="${order.advanceFund==2}">是</c:if></p>
                <select id="advanceFund" name="advanceFund" class="dggui-select">
                    <option value="">请选择</option>
                    <option value="1" <c:if test="${order.advanceFund==1}"> selected="selected" </c:if> >否</option>
                    <option value="2" <c:if test="${order.advanceFund==2}"> selected="selected" </c:if> >是</option>
                </select>
            </td>
        </tr>
        <tr>
            <th>垫资金额(元)：</th>
            <td>
                <p>${order.advanceFundMoney}</p>
                <input id="advanceFundMoney" name="advanceFundMoney" type="text" class="dggui-input"
                       value="${order.advanceFundMoney}">
            </td>
            <th>结案银行：</th>
            <td>
                <p>${order.settlementBank}</p>
                <input id="settlementBank" name="settlementBank" type="text" class="dggui-input"
                       value="${order.settlementBank}" maxlength="50">
            </td>
            <th>垫资注销时间：</th>
            <td>
                <p><fmt:formatDate value="${order.advanceFundCancel}" type="both" pattern="yyyy-MM-dd"/></p>
                <input id="advanceFundCancel" name="advanceFundCancel" type="text" class="dggui-input"
                       value="<fmt:formatDate value="${order.advanceFundCancel}" type="both" pattern="yyyy-MM-dd"/>">
            </td>
            <th>抵押时间：</th>
            <td>
                <p><fmt:formatDate value="${order.mortgageTime}" type="both" pattern="yyyy-MM-dd"/></p>
                <input id="mortgageTime" name="mortgageTime" type="text" class="dggui-input"
                       value="<fmt:formatDate value="${order.mortgageTime}" type="both" pattern="yyyy-MM-dd"/>">
            </td>
        </tr>
        <tr>
            <th>取他权时间：</th>
            <td>
                <p><fmt:formatDate value="${order.takeHisTime}" type="both" pattern="yyyy-MM-dd"/></p>
                <input id="takeHisTime" name="takeHisTime" type="text" class="dggui-input"
                       value="<fmt:formatDate value="${order.takeHisTime}" type="both" pattern="yyyy-MM-dd"/>">
            </td>
            <th>放款金额(元)：</th>
            <td>
                <p>${order.loanMoney}</p>
                <input id="loanMoney" name="loanMoney" type="text" class="dggui-input" value="${order.loanMoney}">
            </td>
            <th>放款时间：</th>
            <td>
                <p><fmt:formatDate value="${order.loanTime}" type="both" pattern="yyyy-MM-dd"/></p>
                <input id="loanTime" name="loanTime" type="text" class="dggui-input"
                       value="<fmt:formatDate value="${order.loanTime}" type="both" pattern="yyyy-MM-dd"/>">
            </td>
            <th>放款时长(天)：</th>
            <td>
                <p>${order.loanTimeDay}</p>
                <input id="loanTimeDay" name="loanTimeDay" type="text" class="dggui-input" value="${order.loanTimeDay}"
                       maxlength="8">
            </td>
        </tr>
        <tr>
            <th>还款时间：</th>
            <td>
                <p id="loan_way_and_date_txt"></p>
                <input name="wayOfLoan" id="wayOfLoan" type="hidden" data-old="${order.wayOfLoan}"
                       value="${order.wayOfLoan}">
                <input name="dateOfLoan" id="dateOfLoan" type="hidden" data-old="${order.dateOfLoan}"
                       value="${order.dateOfLoan}">
            </td>
            <th>还款到期日期：</th>
            <td>
                <p><fmt:formatDate value="${order.repaymentDate}" type="both" pattern="yyyy-MM-dd"/></p>
                <input id="repaymentDate" name="repaymentDate" type="text" class="dggui-input dggui-input-time"
                       value="<fmt:formatDate value="${order.repaymentDate}" type="both" pattern="yyyy-MM-dd"/>">
            </td>
            <th>每期还款金额(元)：</th>
            <td>
                <p>${order.installmentRepayment}</p>
                <input id="installmentRepayment" name="installmentRepayment" type="text" class="dggui-input"
                       value="${order.installmentRepayment}">
            </td>
            <th>后台结算金额(元)：</th>
            <td>
                <p>${order.settlementAmount}</p>
                <input id="settlementAmount" name="settlementAmount" type="text" class="dggui-input"
                       value="${order.settlementAmount}">
            </td>
        </tr>

        <tr>

            <th>渠道返点(元)：</th>
            <td>
                <p>${order.channelRebates}</p>
                <input id="channelRebates" name="channelRebates" type="text" class="dggui-input"
                       value="${order.channelRebates}">
            </td>
            <th>对外返点(元)：</th>
            <td>
                <p>${order.foreignRebates}</p>
                <input id="foreignRebates" name="foreignRebates" type="text" class="dggui-input"
                       value="${order.foreignRebates}">
            </td>
            <th>面积：</th>
            <td>
                <p>${order.area}</p>
                <input id="area" name="area" type="text" maxlength="50" class="dggui-input" value="${order.area}" >
            </td>
            <th>地址：</th>
            <td>
                <p>${order.address}</p>
                <input id="address" name="address" type="text" maxlength="50" class="dggui-input" value="${order.address}" >
            </td>
        </tr>
        <tr>

            <th>说明：</th>
            <td colspan="5">
                <p>${order.accountFor}</p>
                <input id="accountFor" name="accountFor" type="text" class="dggui-input" value="${order.accountFor}"
                       style="max-width: 100%" maxlength="200">
            </td>
        </tr>
        <tr>
            <th class="vertical-top">还款计划表：</th>
            <td colspan="7">
                <div class="upload-compact">
                    <ul>
                        <!-- removeFile 是否可以删除 0-否 1-是；downloadFile 是否可以下载  0-否 1-是；magnifyFile是否可以放大查看图片 0-否，1-是；loadFile初始化时是否加载已上传的文件 0-否，1-是-->
                        <div>
                            <input class="dggui-upload-file" type="file" id="annexUpload_dydk" data-fileid="${order.id}"
                                   data-customerid="${order.customerId}" data-fileType="sc_product_order-hkjhb"
                                   name="file" multiple=""
                                   data-isOne="true" data-multiple="false"
                            <c:if test="${user.id eq order.flowUserId}"> removeFile="1" </c:if>
                                   downloadFile="1" magnifyFile="1" loadFile="1">
                        </div>
                        <div class="colleting-file" <c:if test="${user.id eq order.flowUserId}"> isdel="1" </c:if> id = "upload-params-dydk" data-fileid="${order.id}" data-flag="sc_product_order-hkjhb" data-customerid="${order.customerId}">
                            <c:if test="${user.id eq order.flowUserId}">
                                <div id="upload-dydk" class="client-upload"></div>
                            </c:if>
                        </div>
                    </ul>
                </div>
            </td>
        </tr>
        </tbody>
    </table>
</form>
<script src="${rootUrl}/static/js/rzsc/common/files/annex2.js?v=${version}" type="text/javascript"
        charset="utf-8"></script>
<script>
    var dggdate;
    dggui.use(['dggdate'], function () {
        //初始化文件上传模块
        upload3("upload-dydk","upload-params-dydk");
        initUploadFile("annexUpload_dydk");

        $("#loan_way_and_date_txt").text(joinLoanWayAndTimeTxt('${order.wayOfLoan}', '${order.dateOfLoan}'));
        //$("#thirdparty_name_and_number").html(joinThirdparty('${order.thirdpartyName}','${order.thirdpartyNumber}'));
        dggdate = dggui.dggdate;
        //初始化日期下拉框
        dggdate.render({
            elem: '#approveTime',
            type: 'date'
        });
        dggdate.render({
            elem: '#reportTime',
            type: 'date'
        });
        dggdate.render({
            elem: '#applicationTime',
            type: 'date'
        });
        dggdate.render({
            elem: '#repaymentDate',
            type: 'date'
        });
        dggdate.render({
            elem: '#advanceFundCancel',
            type: 'date'
        });
        dggdate.render({
            elem: '#mortgageTime',
            type: 'date'
        });
        dggdate.render({
            elem: '#takeHisTime',
            type: 'date'
        });
        dggdate.render({
            elem: '#loanTime',
            type: 'date'
        });
        //初始化还款方式
        //commonTreeBookCode("#wayOfLoan", "PAYMENT_METHOD", 1, 1, 1, true);
        //利率方式
        commonTreeBookCodeAndCheck("#rateType", "ORF_LLFS", 1, 1, 1, true, '${order.rateType}');

    });

    var editForm = {
        options: {
            form: '',
            saveFun: function () {

            },
            cancleFun: function () {

            }
        },
        init: function (obj, opt) {
            opt = this.options = $.extend({}, this.options, opt);
            var btnHtm = '<div id="' + this.options.form + '-btn"><a href="javascript:void(0)" class="dggui-btn dggui-btn-sm" onclick="editForm.saveForm(this)">保存</a><a href="javascript:void(0)" class="dggui-btn dggui-btn-primary dggui-btn-sm" onclick="editForm.cancleForm(this)">取消</a></div>'
            $(obj).before(btnHtm);
            $(obj).hide();
            this.dataVal(opt);
        },
        dataVal: function (opt) {
            $(opt.form).find('.edit').addClass('be-editing');
            $.each($(opt.form)[0], function (i, v) {
                var formtype = $(v)[0].type;
                if (formtype == 'radio' || formtype == 'checkbox') {
                    $(v).parents('td').children('p').hide();
                    $(v).parents('td').show();
                } else {
                    if ($(v)[0].id == 'wayOfLoan' || $(v)[0].id == 'dateOfLoan') {
                        $("#loan_way_and_date_txt").val(joinLoanWayAndTime($("#wayOfLoan").val(), $("#dateOfLoan").val()));
                        $("#loan_way_and_date_txt").html(joinLoanWayAndTime('${order.wayOfLoan}', '${order.dateOfLoan}'));
                    } else if ($(v)[0].id == 'thirdpartyName' || $(v)[0].id == 'thirdpartyNumber') {
                        $("#thirdparty_name_and_number").html(joinThirdparty('${order.thirdpartyName}', '${order.thirdpartyNumber}'));
                    } else {
                        $(v).parents('td').children('p').hide();
                        $(v).parents('td').children('div').show();
                        $(v).show();
                    }
                }
            })
        },
        saveForm: function (obj, id) {
            var flag = saveData();
            if (!flag)
                return false;
            var opt = this.options;
            opt.saveFun(opt);
            $(opt.form).find('.edit').removeClass('be-editing');
            $.each($(opt.form)[0], function (i, v) {
                var formtype = $(v)[0].type;
                if (formtype == 'radio' || formtype == 'checkbox') {
                    $(v).parents('td').children('p').show();
                    $(v).parents('td').hide();
                } else if (formtype == 'file') {
                    return false;
                } else {
                    $(v).parents('td').children('p').show();
                    $(v).parents('td').children('div').hide();
                    $(v).hide();
                }
            });
            $(obj).parent().next().show();
            $(obj).parent().remove();
        },
        cancleForm: function (obj) {
            var opt = this.options;
            opt.cancleFun(opt);
            $(opt.form).find('.edit').removeClass('be-editing');
            $.each($(opt.form)[0], function (i, v) {
                var formtype = $(v)[0].type;
                if (formtype == 'radio' || formtype == 'checkbox') {
                    $(v).parents('td').children('p').show();
                    $(v).parents('td').hide();
                } else if ($(v)[0].id == 'wayOfLoan' || $(v)[0].id == 'dateOfLoan') {
                    $("#loan_way_and_date_txt").text(joinLoanWayAndTimeTxt($("#wayOfLoan").attr("data-old"), $("#dateOfLoan").attr("data-old")));
                } else if ($(v)[0].id == 'thirdpartyName' || $(v)[0].id == 'thirdpartyNumber') {
                    var textThird = "";
                    if (checkEmpty('${order.thirdpartyNumber}')) {
                        textThird = '${order.thirdpartyName}' + "/" + '${order.thirdpartyNumber}';
                    } else {
                        textThird = '${order.thirdpartyName}';
                    }
                    $("#thirdparty_name_and_number").text(textThird);
                } else if (formtype == 'file') {
                    return false;
                } else {
                    $(v).parents('td').children('p').show();
                    $(v).parents('td').children('div').hide();
                    $(v).hide();
                }
            });
            $(obj).parent().next().show();
            $(obj).parent().remove();
        }
    }

    //保存
    function saveData() {
        var params = serializeObject($("#dataInfo"));
        params.id = '${order.id}';
        console.log(params);
        if (!verifyLength($("#subBranch"), 100, "最多100个字符"))
            return false;
        if (!isNumberTip($("#loanAmount"), "请输入正确的数字", "不能超过99999999999"))
            return false;
        if (!isNumberTip($("#serviceCharge"), "请输入正确的数字", "比例太大了"))
            return false;
        if (!isNumberTip($("#appraisalCost"), "请输入正确的数字", "不能超过99999999999"))
            return false;
        if (!isNumberTip($("#money"), "请输入正确的数字", "不能超过99999999999"))
            return false;
        if (!isNumberTip($("#approveMoney"), "请输入正确的数字", "不能超过99999999999"))
            return false;
        if (!isNumberTip($("#advanceFundMoney"), "请输入正确的数字", "不能超过99999999999"))
            return false;
        if (!isNumberTip($("#loanMoney"), "请输入正确的数字", "不能超过99999999999"))
            return false;
        if (!isIntNumberTip($("#loanTimeDay"), "请输入正整数"))
            return false;
        if (!isNumberTip($("#installmentRepayment"), "请输入正确的数字", "不能超过99999999999"))
            return false;
        if (!isNumberTip($("#settlementAmount"), "请输入正确的数字", "不能超过99999999999"))
            return false;
        if (!isNumberTip($("#channelRebates"), "请输入正确的数字", "不能超过99999999999"))
            return false;
        if (!isNumberTip($("#foreignRebates"), "请输入正确的数字", "不能超过99999999999"))
            return false;
        if (!isNumberTip($("#appliedAmount"), "请输入正确的数字", "不能超过99999999999"))
            return false;
        if (!verifyLength($("#area"), 50, "最多50个字符"))
            return false;
        if (!verifyLength($("#address"), 50, "最多50个字符"))
            return false;
        dggui.dialog.loading();
        $.post(sysInfo.basePath + "/order_detail/order_info_save.do", {orderStr: JSON.stringify(params)}, function (result) {
            dggui.dialog.loading('close');
            if (result.code == 0) {
                dggui.dialog.succeed('保存成功！');
                loadProductData();
            } else {
                dggui.dialog.errors(result.msg);
            }

        })
    }
</script>